#pragma once
#include "../widgets.h"
#include <QObject>
#include <QJsonObject>
#include <functional>
#include <map>

class QWebEnginePage;
class QbWebWidget;

struct WebResponse
{
    bool handled = false;
    QString res;
    QString jsCb;
};

typedef std::function<WebResponse(const QString&, const QJsonValue&)> WebHandlerFunc;
class S_WIDGETS_EXPORT WebReqHandler :public QObject
{
    Q_OBJECT
public:
    explicit WebReqHandler(QObject* parent = nullptr);

    static void registerHandlers(const QString& req, WebHandlerFunc func);

public slots:
    int cefQuery(int sid, QJsonObject msg);

signals:
	void result(int sid, QString res, QString cb);   //信号传参

private:
    QbWebWidget* m_widget = nullptr;
    QString m_params = nullptr;
    static std::multimap<QString, WebHandlerFunc>   s_handlers;
};
